package cn.wolfcode.rbac.web.interceptor;

import cn.wolfcode.rbac.domain.Employee;
import cn.wolfcode.rbac.util.UserContext;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by Administrator on 2020/6/12 0012.
 */
@Component
public class CheckLoginIntercptor implements HandlerInterceptor {

    /**
     * preHandler 前置拦截
     * 返回true 表示放行
     * 返回false 表示拦截
     */
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //从session当中去employee的对象, 如果有这个对象说明已经登录了, 如果没有这个对象说明之前是没有登录的
        Employee employee = UserContext.getCurrent();
        if(employee == null){
            response.sendRedirect("/login.jsp");
            return false;
        }
        return true;
    }
}
